package dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.cfg.CreateKeySecondPass;

import dao.utils.GenericHibernateDAO;
import domain.Articulos;
import domain.Empleados;
import domain.Iva;
import domain.Proveedor;

public class ArticulosDAOImpl extends GenericHibernateDAO implements
		ArticulosDAO {

	public ArticulosDAOImpl(Session s) {
		super(s);
	}

	public Articulos findByDni(int ID) {
		Articulos articulo = (Articulos) getSession()
				.createQuery("From Articulos as art where art.idArticulo=?")
				.setInteger(0, ID).uniqueResult();
		return articulo;
	}

	@Override
	public List<Articulos> findAll() {
		// TODO Auto-generated method stub
		Query q = getSession().createQuery("From Articulos");
		return q.list();

	}

	@Override
	public List<Articulos> findByArticuloVenta(boolean sale) {
		// TODO Auto-generated method stub
		Query q = getSession().createQuery(
				"From Articulos as art where art.venta = " + sale + "");
		return q.list();

	}

	@Override
	public List<Articulos> findByArticuloInventariable(boolean inventoried) {
		// TODO Auto-generated method stub
		Query q = getSession().createQuery(
				"From Articulos as art where art.inventariable = "
						+ inventoried + "");
		return q.list();

	}

	@Override
	public List<Articulos> findByArticuloVentaInventariable(boolean sale,
			boolean inventoried) {
		// TODO Auto-generated method stub
		Query q = getSession().createQuery(
				"From Articulos as art where art.venta = " + sale
						+ " and art.inventariable = " + inventoried + "");
		return q.list();

	}

	@Override
	public Articulos findPorID(int idart) {
		// TODO Auto-generated method stub
		try {
			Articulos articulo = (Articulos) getSession()
					.createQuery(
							"FROM Articulos AS art WHERE art.idArticulo =?")
					.setInteger(0, idart).uniqueResult();
			System.out.println(articulo.getIdArticulo());
			return (articulo);
		} catch (Exception e) {
			System.out.println(e.getMessage());
			return (null);
		}
		

	}

	@Override
	public void modArticulo(Articulos articulo) {

		getSession().update(articulo);

	}

	@Override
	public boolean insertar(Articulos Articulo) {
		getSession().save(Articulo);
		return true;
	}

	@Override
	public void elminarArticulo(Articulos articulo) {
		// TODO Auto-generated method stub
		getSession().delete(articulo);

	}

	@Override
	public boolean modificarStock(Articulos article) {
		// TODO Auto-generated method stub
		getSession().update(article);
		// QUERY = UPDATE `hldb`.`articulos` SET `STOCK` = 'stock' WHERE
		// `articulos`.`idArticulo` =ID;
		return false;
	}

	@Override
	public Articulos findByID(String idart) {
		// TODO Auto-generated method stub
		return null;
	}
}
